package com.hdoit.ares.web.insu.providers;

import java.util.ArrayList;
import java.util.List;

import com.hdoit.ares.logical.insu.model.InsuranceCompany;
import com.hdoit.ares.logical.insu.service.IInsuranceCompanyService;
import com.tennetcn.common.aop.CommonApplicationContextUtil;
import com.tennetcn.common.message.ListItem;
import com.tennetcn.component.attribute.provider.ISingleOptionListProvider;
import com.tennetcn.web.cbase.providers.base.DataListProviderBase;

public class InsuranceCompanyProvider extends DataListProviderBase implements ISingleOptionListProvider<ListItem>  {

	@Override
	public List<ListItem> getDataList(Object viewData) {
		List<InsuranceCompany> insuranceCompanyList=getInsuranceCompanyList();
		if(insuranceCompanyList==null||insuranceCompanyList.size()<=0){
			return null;
		}
		dataList=new ArrayList<ListItem>();
		ListItem item;
		for (InsuranceCompany insuranceCompany:insuranceCompanyList) {
			item=new ListItem();
			item.setText(insuranceCompany.getShortName());
			item.setValue(insuranceCompany.getId());
			
			dataList.add(item);
		}

		return dataList;
	}

	private List<InsuranceCompany> getInsuranceCompanyList() {
		IInsuranceCompanyService insuranceCompanyService=(IInsuranceCompanyService) CommonApplicationContextUtil.getCurrentContext().getBean(IInsuranceCompanyService.class);
		
		List<InsuranceCompany> insuranceCompanyList=new ArrayList<InsuranceCompany>();
		insuranceCompanyList = insuranceCompanyService.queryList();
		
		return insuranceCompanyList;
	}

}
